package com.cmit.lee.myaop.interceptor;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

import java.lang.reflect.Method;

/**
 * <br/>
 *
 * @author liyuanchang
 * @version V1.0
 * @email liyuanchang@chinamobile.com
 * @date 2020-04-15 20:56
 */
public abstract class MethodBeforeInterceptor implements MethodInterceptor {
    /**
     * 在方法调用前执行
     * @param method
     * @param args
     * @param target
     * @throws Throwable
     */
    public abstract void before(Method method, Object[] args, Object target) throws Throwable;

    @Override
    public Object invoke(MethodInvocation invocation) throws Throwable {
        // 先调用before方法
        this.before(invocation.getMethod(), invocation.getArguments(), invocation.getThis());
        // 继续执行调用链
        return invocation.proceed();
    }
}
